#include <iostream>
#include <cstring>
using namespace std;

typedef pair<int, int> PII;

const int N = 100010;
const int INF = 0x3f3f3f3f;
int h[N], e[N], ne[N], w[N], idx = 0;
PII q[N];
int l = 0, r = -1;
int n, m, a, b, c;
int dist[N];
bool st[N];
int cnt[N]; //用来记录起点现阶段到此点的步数

void add(int a, int b, int c)
{
    e[idx] = b;
    ne[idx] = h[a];
    w[idx] = c;
    h[a] = idx++;
    return;
}

bool spfa(int x = 1, int y = n)
{
    dist[1] = 0;
    for (int i = 1; i <= n; ++i)
        q[++r] = PII(i, dist[i]), st[i] = true;
    while (r >= l)
    {
        PII p = q[l++];
        int t = p.first;
        st[t] = false;
        for (int i = h[t]; i != -1; i = ne[i])
        {
            int j = e[i];
            if (dist[j] > dist[t] + w[i])
            {
                dist[j] = dist[t] + w[i];
                cnt[j] = cnt[t] + 1; //在起点到j的基础上多走了一步t到j
                if (cnt[j] >= n)     //如果最短路的步长超过了n-1(既顶多所有点都跑了一圈)
                    return true;     //那就是存在负权环
                if (!st[j])
                    q[++r] = PII(j, dist[j]), st[j] = true;
            }
        }
    }
    return false; //能成功从循环里面出来，代表没有负权回路
}

int main()
{
    memset(h, -1, sizeof h);
    memset(dist, 0x3f, sizeof dist);
    memset(st, false, sizeof st);
    memset(cnt, 0, sizeof cnt);
    cin >> n >> m;
    while (m--)
    {
        cin >> a >> b >> c;
        add(a, b, c);
    }
    bool t = spfa();
    if (t)
        cout << "Yes";
    else
        cout << "No";
    return 0;
}